package com.module.app.base.loadsir;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.kingja.loadsir.callback.Callback;
import com.module.app.R;


public class EmptyCallback extends Callback {

    @Override
    protected int onCreateView() {
        return R.layout.app_layout_loadsir_empty;
    }

    @Override
    protected void onViewCreate(Context context, View view) {

    }

    /**
     * @param subtitle 副标题
     * @param title    标题
     */
    public static void setView(View view, int logo, String title, String subtitle, String btnText, View.OnClickListener listener) {
        if (view != null) {
            if (logo > 0) {
                ImageView imageView = getLogoImageView(view);
                imageView.setImageResource(logo);
            }

            TextView textView = getSubTitleView(view);
            if (!TextUtils.isEmpty(subtitle)) {
                textView.setText(subtitle);
                textView.setVisibility(View.VISIBLE);
            } else {
                textView.setVisibility(View.GONE);
            }

            TextView tv_title = getTitleView(view);
            if (!TextUtils.isEmpty(title)) {
                tv_title.setText(title);
                tv_title.setVisibility(View.VISIBLE);
            } else {
                tv_title.setVisibility(View.GONE);
            }

            TextView tv_btn = getBtn(view);
            if (!TextUtils.isEmpty(btnText)) {
                tv_btn.setText(btnText);
                tv_btn.setVisibility(View.VISIBLE);
            } else {
                tv_btn.setVisibility(View.GONE);
            }
            tv_btn.setOnClickListener(listener);

        }
    }


    public ViewGroup getLayout(View view) {
        ViewGroup layout = view.findViewById(R.id.layout);
        return layout;
    }

    public ViewGroup getLogoView(View view) {
        ViewGroup layout_logo = view.findViewById(R.id.layout_logo);
        return layout_logo;
    }

    public static ImageView getLogoImageView(View view) {
        ImageView layout_logo = view.findViewById(R.id.loadsir_iv_logo);
        return layout_logo;
    }

    public static TextView getTitleView(View view) {
        return view.findViewById(R.id.loadsir_tv_title);
    }

    public static TextView getSubTitleView(View view) {
        return view.findViewById(R.id.tv_subtitle);
    }

    public static TextView getBtn(View view) {
        return view.findViewById(R.id.tv_btn);
    }
}
